import {
  Component,
  OnInit,
  ChangeDetectionStrategy,
  Output,
  EventEmitter,
} from '@angular/core';

export enum Flag {
  Normal = 'sort',
  Descending = 'sort-descending',
  Ascending = 'sort-ascending',
}

@Component({
  selector: 'sort-btn',
  templateUrl: './sort-btn.component.html',
  styleUrls: ['./sort-btn.component.less'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SortBtnComponent implements OnInit {
  flag = Flag.Normal;

  @Output() change = new EventEmitter<Flag>();

  constructor() {}

  ngOnInit(): void {}

  changeFlag() {
    console.log(this.flag);
    switch (this.flag) {
      case Flag.Normal:
        this.flag = Flag.Descending;
        break;
      case Flag.Descending:
        this.flag = Flag.Ascending;
        break;
      case Flag.Ascending:
        this.flag = Flag.Normal;
        break;
    }
    this.change.emit(this.flag);
  }
}
